package com.junzhiit.nengji.cms.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ReportService;
import com.junzhiit.nengji.cms.web.vo.AnalysisReportVO;
import com.junzhiit.nengji.cms.web.vo.GoodsListVO;
import com.junzhiit.nengji.cms.web.vo.OrdersAndDetailsVO;
import com.junzhiit.nengji.cms.web.vo.OrdersAndGoodsVO;
import com.junzhiit.nengji.cms.web.vo.PayHistoryVO;
import com.junzhiit.nengji.model.enums.AnalysisType;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("report")
public class ReportController extends BaseController {

	@Autowired
	private ReportService reportService;
	
	@ApiOperation(value="导出交易分析统计数据")
	@RequestMapping(value="/transaction/all/analysis",method=RequestMethod.POST)
	public void exportTransactionAnalysisAllExcel(HttpServletResponse response,HttpServletRequest request,String sessionId,Integer analysisType,String date,String startTime,String endTime){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notNull(analysisType, "analysisType is required");
		if(analysisType==AnalysisType.DAY.toIntValue()||analysisType==AnalysisType.MONTH.toIntValue()){
			AssertUtil.notBlank(date, "date is required");
		} else if(analysisType==AnalysisType.CUSTOM.toIntValue()){
			AssertUtil.notBlank(startTime, "startTime is required");
			AssertUtil.notBlank(endTime, "endTime is required");
		}
		reportService.exportTransactionAnalysisAllExcel(response,request,sessionId,analysisType,date,startTime,endTime);
	}

	@ApiOperation(value="导出交易分析详细数据")
	@RequestMapping(value="/transaction/analysis",method=RequestMethod.POST)
	public void exportTransactionAnalysisExcel(HttpServletResponse response,HttpServletRequest request,String sessionId,Integer exportType){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notNull(exportType, "exportType is required");
		reportService.exportTransactionAnalysisExcel(response,request,sessionId,exportType);
	}
	
	@ApiOperation(value="导出消费记录数据")
	@RequestMapping(value="/consume/record",method=RequestMethod.POST)
	public void exportConsumeData(HttpServletResponse response,HttpServletRequest request,String sessionId,PayHistoryVO payHistoryVO){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		reportService.exportConsumeRecordExcel(response, request, sessionId, payHistoryVO);
	}
	
	@ApiOperation(value="导出消费排行数据")
	@RequestMapping(value="/consume/ranking",method=RequestMethod.POST)
	public void exportConsumeRankingData(HttpServletResponse response,HttpServletRequest request,String sessionId,PayHistoryVO payHistoryVO){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		reportService.exportConsumeRankingExcel(response, request, sessionId, payHistoryVO);
	}
	
	@ApiOperation(value="导出一个用户的消费数据")
	@RequestMapping(value="/user/consume",method=RequestMethod.POST)
	public void exportUserConsumeData(HttpServletResponse response,HttpServletRequest request,String sessionId,String userId){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notBlank(userId, "userId is required");
		reportService.exportUserConsumeExcel(response, request, sessionId, userId);
	}
	
	@ApiOperation(value="导出店铺订单及订单明细")
	@RequestMapping(value="/orders/details",method=RequestMethod.POST)
	public void exportOrdersAndDetailsExcel(HttpServletResponse response, HttpServletRequest request,OrdersAndDetailsVO oadv){
		reportService.exportOrdersAndDetailsExcel(response,request,oadv);
	}
	
	@ApiOperation(value="导出店铺产品列表")
	@RequestMapping(value="/shop/goods/list",method=RequestMethod.POST)
	public void exportShopGoodsListExcel(HttpServletResponse response,HttpServletRequest request,GoodsListVO glv){
		reportService.exportShopGoodsListExcel(response, request, glv);
	}
	
	@ApiOperation(value="导出订单历史数据")
	@RequestMapping(value="/orders/history",method=RequestMethod.POST)
	public void exportOrdersAndGoodsExcel(HttpServletResponse response, HttpServletRequest request,OrdersAndGoodsVO ordersAndGoodsVO){
		reportService.exportDataReportExcel(response,request,ordersAndGoodsVO);
	}
	
	@ApiOperation(value="导出品牌交易分析统计数据")
	@RequestMapping(value="/chain/transaction/analysis",method=RequestMethod.POST)
	public void exportChainTransactionAnalysis(HttpServletResponse response,HttpServletRequest request,AnalysisReportVO analysisReportVO){
		AssertUtil.notBlank(analysisReportVO.getSessionId(), "sessionId is required");
		AssertUtil.notNull(analysisReportVO.getAnalysisType(), "analysisType is required");
		if(analysisReportVO.getAnalysisType()==AnalysisType.DAY.toIntValue()||analysisReportVO.getAnalysisType()==AnalysisType.MONTH.toIntValue()){
			AssertUtil.notBlank(analysisReportVO.getDate(), "date is required");
		} else if(analysisReportVO.getAnalysisType()==AnalysisType.CUSTOM.toIntValue()){
			AssertUtil.notBlank(analysisReportVO.getStartTime(), "startTime is required");
			AssertUtil.notBlank(analysisReportVO.getEndTime(), "endTime is required");
		}
		reportService.exportChainTransactionAnalysis(response,request,analysisReportVO);
	}
	
	@ApiOperation(value="导出品牌交易分析详细数据")
	@RequestMapping(value="/chain/transaction/analysis/details",method=RequestMethod.POST)
	public void exportChainTransactionAnalysisList(HttpServletResponse response,HttpServletRequest request,AnalysisReportVO arv){
		AssertUtil.notBlank(arv.getSessionId(), "sessionId is required");
		AssertUtil.notNull(arv.getExportType(), "exportType is required");
		reportService.exportChainTransactionAnalysisList(response,request,arv.getSessionId(),arv.getExportType(),arv.getShopId());
	}
	
	@ApiOperation(value="导出商品分析数据")
	@RequestMapping(value="/goods/analysis",method=RequestMethod.POST)
	public void exportGoodsAnalysisExcel(HttpServletResponse response,HttpServletRequest request,String sessionId,String startTime,String endTime,String shopId){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notBlank(startTime, "startTime is required");
		AssertUtil.notBlank(endTime, "endTime is required");
		reportService.exportGoodsAnalysisExcel(response, request, sessionId, startTime, endTime, shopId);
	}
	
	@ApiOperation(value="导出品牌商品分析数据")
	@RequestMapping(value="/goods/analysis/all",method=RequestMethod.POST)
	public void exportAllGoodsAnalysisExcel(HttpServletResponse response,HttpServletRequest request,String sessionId,String startTime,String endTime,String shopId){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notBlank(startTime, "startTime is required");
		AssertUtil.notBlank(endTime, "endTime is required");
		reportService.exportAllGoodsAnalysisExcel(response,request,sessionId,startTime,endTime,shopId);
	}
	
	@ApiOperation(value="导出商品分析数据")
	@RequestMapping(value="/shop/analysis",method=RequestMethod.POST)
	public void exportShopAnalysisExcel(HttpServletResponse response,HttpServletRequest request,String sessionId,String startTime,String endTime,String shopId){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notBlank(startTime, "startTime is required");
		AssertUtil.notBlank(endTime, "endTime is required");
		reportService.exportShopAnalysisExcel(response, request, sessionId, startTime,endTime,shopId);
	}
}
